// Created by WXX on 2021/12/18 23:20
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * 执行用时：0 ms, 在所有 C++ 提交中击败了100.00%的用户
 * 内存消耗：8.1 MB, 在所有 C++ 提交中击败了88.59%的用户
 */
class Solution {
public:
    int maxAscendingSum(vector<int> &nums) {
        int res = 0;
        for (int i = 0, j = 0, s = 0; i < nums.size(); i++) {
            while (j + 1 < nums.size() && nums[j] < nums[j + 1]) s += nums[j++];
            s += nums[j++];
            res = max(res, s);

            i = j - 1;
            s = 0;
        }
        return res;
    }
};

int main() {

    vector<int> nums = {1, 2, 30, 30, 15, 5, 50};
    cout << Solution().maxAscendingSum(nums) << endl;  // 55

    return 0;
}
